const app = getApp();
Page({
  data:{
    name:'',
    phoneNumber :'',
    istrue:false,
    avatarUrl: ''//用户头像
  },
  toInfo: function () {
    wx.navigateTo({
      url: './info/info'
    })
  },
  toBank: function () {
    wx.navigateTo({
      url: './bank/bank'
    })
  },
  toSetPayPwd: function () {
    wx.navigateTo({
      url: '../my/setpaypwd/setpaypwd'
    })
  },
  touserd:function(){
    wx.navigateTo({
      url: '../teamuser/teamuser'
    })
  },
  toSetLoginPwd: function () {
    wx.navigateTo({
      url: '../password/password?from=loginpwd'
    })
  },
  onShow:function(){
    console.log(11111)
    this.setData({
      istrue: app.globalData.baseInfo.teamTransfer
    })
    console.log(app.globalData.baseInfo)
    console.log(2222)
    // 用户信息
    const _this = this;
    wx.request({
      url: app.globalData.path + 'services/app/applets/GetCurrentLoginUserInfo',
      data: {},
      method: 'POST',
      header: {
        'content-type': 'application/json', // 默认值
        'Authorization': 'Bearer ' + app.globalData.authorization
      },
      success: function (res) {
        console.log(res.data);
        if (res.statusCode == 401) {
          wx.removeStorage({
            key: 'token',
            success: function (res) {
            },
          })
          wx.reLaunch({
            url: '/pages/login/login'
          })
        }
        if (res.data.success) {
          app.globalData.baseInfo = res.data.result;
          _this.setData({
            name: res.data.result.name,
            phoneNumber: res.data.result.phoneNumber,
            avatarUrl: res.data.result.profilePicturePath
          })
        } else {
          wx.showToast({
            title: res.data.error.message,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  // 退出
  quitLogin:function(){
    wx.showModal({
      title: '确认信息',
      content: '确认要退出登录吗？',
      confirmText: "仍要退出",
      cancelText: "取消",
      success: function (res) {
        console.log(res);
        if (res.confirm) {
          app.globalData.authorization = '';
          wx.removeStorage({
            key: 'token',
            success: function (res) {
              wx.redirectTo({
                url: '../login/login'
              })
            },
          })
          
        }
      }
    });
  },
  // 分享
  onShareAppMessage: function (res) {
    let title = '';
    if (this.data.name) {
      title = this.data.name + '邀请你使用锦和薪金宝收取佣金！';
    } else {
      title = '你的好友邀请你使用锦和薪金宝收取佣金！'
    }
    var shareObj = {
      title: title,
      path: 'pages/login/login',
      imageUrl: '../../static/icon_share.png',
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') { }
      },
      fail: function (res) {
        if (res.errMsg == 'shareAppMessage:fail cancel') { }
        else if (res.errMsg == 'shareAppMessage:fail') { }
      }
    }
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return shareObj;
  },
})